package org.qh.ai.controller.tripartite;

import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import org.qh.ai.domain.dto.TaskConditionDTO;
import org.qh.ai.util.MjOkHttpUtil;
import org.springframework.web.bind.annotation.*;


/**
 * 绘画任务查询
 *
 * @author qianhong
 * @date 2025-05-03
 */

@RestController
@RequestMapping("/mj/task")
@RequiredArgsConstructor
@Slf4j
public class TaskController {

    private final MjOkHttpUtil mjOkHttpUtil;

    /**
     * 指定ID获取任务
     * @param id
     * @return
     */
	@GetMapping("/{id}/fetch")
    public String fetch(@PathVariable String id) {
        String url = "mj/task/" + id + "/fetch";
        Request request = mjOkHttpUtil.createGetRequest(url);
        return mjOkHttpUtil.executeRequest(request);
    }

    /**
     * 根据ID列表查询任务
     * @param conditionDTO
     * @return
     */
	@PostMapping("/list-by-condition")
	public String listByIds(@RequestBody TaskConditionDTO conditionDTO) {
        String url = "mj/task/list-by-condition";
        String conditionJson = JSONUtil.toJsonStr(conditionDTO);
        Request request = mjOkHttpUtil.createPostRequest(url,conditionJson);
        return mjOkHttpUtil.executeRequest(request);
	}

    /**
     * 获取任务图片的seed
     * @param id
     * @return
     */
    @GetMapping("/{id}/image-seed")
    public String getSeed(@PathVariable String id) {
        String url = "mj/task/" + id + "/image-seed";
        Request request = mjOkHttpUtil.createGetRequest(url);
        return mjOkHttpUtil.executeRequest(request);
    }

}
